require('babel-register');
import express from "express";
import webpack from "webpack";
import config from "../build/config";
import webpackConfig from "../build/webpack.config.babel";
import path from "path";

const app = new express();


// gzip 压缩, 测试环境才需要,正式环境需要运维在http server上做这个事1
const compiler = webpack(webpackConfig());
const options = {
  publicPath: config.outPutPublicPath,
  noInfo: true,
  hot: true,
  stats: { color: true }
};
app.use(require("webpack-dev-middleware")(compiler, options));
app.use(require("webpack-hot-middleware")(compiler));
app.use("/public", express.static(path.resolve(__dirname, "../public")));


// ssr模板 中间件
// app.use(require("../dist/server-entry"));
const server = app.listen(config.ssrPort, () => {
  const { ssrPort } = server.address();
  console.log(`Listened at http://localhost:${ssrPort}`);
});
